
/* ************************************************************************************* 
 * CREATED BY:          MYGENERATION
 * CREATED DATE:        12/25/2008
 * PROJECT:             MCWEBSITE
 * PURPOSE:             websiteLanguageDAL class
 * MODIFIED BY:         None
 * MODIFIED DATE:       None
 * MODIFIED REASON:     None
 * NOTES:               None
 **************************************************************************************/
 
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Configuration;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using System.Web.Configuration;
using MCWEBSITE.ENTITY;

namespace MCWEBSITE.DAL
{
    public class websiteLanguageDAL
    {
        #region  Properties
		 
		public static string FIELD_LANGUAGECODE = "LanguageCode";  
		public static string FIELD_LANGUAGENAME = "languageName";  
		public static string FIELD_DESCRIPTION = "Description"; 
		public static string ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["ContentConnectionString"].ToString();

        #endregion

        #region Protected methods

        /// <summary>
        /// Select entity of websiteLanguage
        /// </summary>
        /// <param name="LanguageCode">Primary Keys</param>
        /// <returns>Collection of websiteLanguageInfo</returns>
        public static websiteLanguageInfo SelectOne(string LanguageCode)
        {
            websiteLanguageInfo _websiteLanguageInfo = new websiteLanguageInfo();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteLanguageSelectOne", LanguageCode);
                if (dr.Read())
                    setwebsiteLanguageInfo(dr, ref _websiteLanguageInfo);
                return _websiteLanguageInfo;
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Select all websiteLanguage
        /// </summary>
        /// <returns>Collection of websiteLanguageInfo</returns>
        public static List<websiteLanguageInfo> SelectAll()
        {
            List<websiteLanguageInfo> lstwebsiteLanguage = new List<websiteLanguageInfo>();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteLanguageSelectAll");
                setListwebsiteLanguageInfo(ref dr, ref lstwebsiteLanguage);
                return lstwebsiteLanguage;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Select
        /// </summary>
        /// <param name="websiteLanguagenfo">Modify this method adapting your need</param>
        /// <returns>Collection of websiteLanguageInfo</returns>
        public static List<websiteLanguageInfo> SelectFilters()
        {
            string criterias = string.Empty;
            List<websiteLanguageInfo> lstwebsiteLanguage = new List<websiteLanguageInfo>();
            SqlDataReader dr = null;
            try 
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteLanguageSelectByFilters");
                setListwebsiteLanguageInfo(ref dr, ref lstwebsiteLanguage);
                return lstwebsiteLanguage;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Insert websiteLanguage
        /// </summary>
        /// <param name="websiteLanguageInfo">Entity of websiteLanguage</param>
        /// <returns>error code</returns>
        public static int Insert(websiteLanguageInfo _websiteLanguageInfo)
        {
           try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_mc_websiteLanguageInsert" 
											, _websiteLanguageInfo.languageName
											, _websiteLanguageInfo.Description
											);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }
        
        /// <summary>
        /// Update websiteLanguage
        /// </summary>
        /// <param name="websiteLanguageInfo">Entity of websiteLanguage</param>
        /// <returns>error code</returns>
        public static int Update(websiteLanguageInfo _websiteLanguageInfo)
        {            
            try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_mc_websiteLanguageUpdate"
											, _websiteLanguageInfo.LanguageCode
											, _websiteLanguageInfo.languageName
											, _websiteLanguageInfo.Description
											);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        /// <summary>
        /// Delete SchoolAdmin
        /// </summary>
        /// <param name="LanguageCode">Primary Key</param>
        /// <returns>error code</returns>
        public static int Delete(string LanguageCode)
        {
           try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_mc_websiteLanguageDelete", LanguageCode);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        #endregion

        #region "Utilities method"
		
        private static void setListwebsiteLanguageInfo(ref SqlDataReader dr, ref List<websiteLanguageInfo> lstwebsiteLanguage)
        {
            websiteLanguageInfo _websiteLanguageInfo = null;
            while (dr.Read())
            {
                _websiteLanguageInfo = new websiteLanguageInfo();
                setwebsiteLanguageInfo(dr, ref _websiteLanguageInfo);
                lstwebsiteLanguage.Add(_websiteLanguageInfo);
            }
        }

        private static void setwebsiteLanguageInfo(SqlDataReader dr, ref websiteLanguageInfo _websiteLanguageInfo)
        {
			_websiteLanguageInfo.LanguageCode = dr[websiteLanguageDAL.FIELD_LANGUAGECODE] != DBNull.Value ? Convert.ToString(dr[websiteLanguageDAL.FIELD_LANGUAGECODE]) : string.Empty;
			_websiteLanguageInfo.languageName = dr[websiteLanguageDAL.FIELD_LANGUAGENAME] != DBNull.Value ? Convert.ToString(dr[websiteLanguageDAL.FIELD_LANGUAGENAME]) : string.Empty;
			_websiteLanguageInfo.Description = dr[websiteLanguageDAL.FIELD_DESCRIPTION] != DBNull.Value ? Convert.ToString(dr[websiteLanguageDAL.FIELD_DESCRIPTION]) : string.Empty;
			                        
        }
        #endregion Methods

        #region Private Members

        private static string TABLE_NAME = "[mc_websiteLanguage]";

        #endregion
    }
}

		